﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnemyAI : MonoBehaviour
{
    [HideInInspector]
    public bool isBeAttacked;

    [SerializeField]
    private Transform fromPoint;
    [SerializeField]
    private Transform toPoint;
    [SerializeField]
    private float speed;

    public GameObject destroyedEffect;

    private SpriteRenderer sr;
    // Start is called before the first frame update
    void Start()
    {
        sr = GetComponent<SpriteRenderer>();
        transform.position = fromPoint.position;
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    private int direction = -1;
    private void FixedUpdate()
    {
        transform.Translate(new Vector2(speed * direction * Time.deltaTime, 0f), Space.World);
        if (transform.position.x < toPoint.position.x)
        {
            sr.flipX = true;
            direction *= -1;
        }
        else if (transform.position.x > fromPoint.position.x)
        {
            sr.flipX = false;
            direction *= -1;
        }
    }
}
